package com.googlecode.connectlet.crypto.cipher.mode;

public class Pkcs5PaddingEncipherorFinal implements FinalBlock {
	private EcbNoPaddingEncipheror enc;

	public Pkcs5PaddingEncipherorFinal(EcbNoPaddingEncipheror enc) {
		this.enc = enc;
	}

	@Override
	public int doFinal(byte[] output, int outputOffset) {
		int nPadding = enc.blockSize - enc.blockOffset;
		for (int i = enc.blockOffset; i < enc.blockSize; i ++) {
			enc.block[i] = (byte) nPadding;
		}
		enc.encryptNext(output, outputOffset);
		return enc.blockSize;
	}
}